Python: Fix tuple parsing for parenthesized element with trailing comma#6811
Merged
knutwannheden merged 1 commit intomainfrom Feb 25, 2026
Merged
Python: Fix tuple parsing for parenthesized element with trailing comma#6811knutwannheden merged 1 commit intomainfrom
knutwannheden merged 1 commit intomainfrom
Conversation
…ma outside
The parser incorrectly identified `(` as the tuple's opening paren in
expressions like `("a"),` where the parentheses wrap the element and the
trailing comma outside creates an implicit single-element tuple. This caused
the token index to fall behind the AST position, eventually crashing with
`'NoneType' object has no attribute 'value_source'` when parsing string
literals in type annotations like `Literal["..."]` later in the file.
macsux
pushed a commit
that referenced
this pull request
Feb 27, 2026
…ma outside (#6811) The parser incorrectly identified `(` as the tuple's opening paren in expressions like `("a"),` where the parentheses wrap the element and the trailing comma outside creates an implicit single-element tuple. This caused the token index to fall behind the AST position, eventually crashing with `'NoneType' object has no attribute 'value_source'` when parsing string literals in type annotations like `Literal["..."]` later in the file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
'NoneType' object has no attribute 'value_source') when parsing files containing single-element tuples where parentheses wrap the element and the trailing comma is outside, e.g.("a"),(as the tuple's opening paren in such expressions, causing the token index to progressively fall behind the AST position, eventually crashing when encountering string literals in type annotations likeLiteral["..."])is followed by,with no,inside the parens, distinguishing("a"),(grouping parens + implicit tuple) from("a",)(tuple parens)Test plan
test_literal_string_type_hint_with_assignment— minimal reproduction of the original crashtest_single_element_tuple_with_trailing_comma_outside_parens— inline casetest_single_element_tuple_with_trailing_comma_outside_parens_multiline— multi-line string concatenation casepreview_long_strings.py) parses successfully